﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Golf.Model;
namespace Golf.BLL
{
    /// <summary>
    /// Golf_OrderStateCode
    /// </summary>
    public partial class Golf_OrderStateCode
    {
        private readonly Golf.DAL.Golf_OrderStateCode dal = new Golf.DAL.Golf_OrderStateCode();
        public Golf_OrderStateCode()
        { }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Golf.Model.Golf_OrderStateCode model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Golf.Model.Golf_OrderStateCode model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Golf.Model.Golf_OrderStateCode GetModel(int Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Golf.Model.Golf_OrderStateCode GetModelByCache(int Id)
        {

            string CacheKey = "Golf_OrderStateCodeModel-" + Id;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(Id);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Golf.Model.Golf_OrderStateCode)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Golf.Model.Golf_OrderStateCode> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Golf.Model.Golf_OrderStateCode> DataTableToList(DataTable dt)
        {
            List<Golf.Model.Golf_OrderStateCode> modelList = new List<Golf.Model.Golf_OrderStateCode>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Golf.Model.Golf_OrderStateCode model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Golf.Model.Golf_OrderStateCode();
                    if (dt.Rows[n]["Id"] != null && dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["OrderStateName"] != null && dt.Rows[n]["OrderStateName"].ToString() != "")
                    {
                        model.OrderStateName = dt.Rows[n]["OrderStateName"].ToString();
                    }
                    if (dt.Rows[n]["OrderStateCodeRemarks"] != null && dt.Rows[n]["OrderStateCodeRemarks"].ToString() != "")
                    {
                        model.OrderStateCodeRemarks = dt.Rows[n]["OrderStateCodeRemarks"].ToString();
                    }
                    if (dt.Rows[n]["AdminId"] != null && dt.Rows[n]["AdminId"].ToString() != "")
                    {
                        model.AdminId = int.Parse(dt.Rows[n]["AdminId"].ToString());
                    }
                    if (dt.Rows[n]["AddTime"] != null && dt.Rows[n]["AddTime"].ToString() != "")
                    {
                        model.AddTime = DateTime.Parse(dt.Rows[n]["AddTime"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        #endregion  Method
    }
}

